<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once( BASEPATH.'libraries/smarty30rc2/libs/Smarty.class.php' );
class CI_Smarty extends Smarty {
	function __construct() {
		parent::__construct();
		// Z, split() depreciatated, replace with explode
		//$uri = split('/', str_replace('/index.php', '',  $_SERVER['REQUEST_URI']));
		$uri = explode('/', str_replace('/index.php', '',  $_SERVER['REQUEST_URI']));
		$uri = empty($uri[2]) ? 'h' : $uri[2];
		
		$this->template_dir = HPATH."/application/views/";
		$this->compile_dir  = HPATH."/tmp/$uri/";
		$this->cache_dir    = HPATH."/tmp/$uri/cache/";
		log_message('debug', "Smarty Class Initialized");
	}

	function view($template, $data = array(), $return = FALSE) {
		foreach ($data as $key => $val) {
			$this->assign($key, $val);
		}

		if ($return == FALSE) {
			$CI =& get_instance();
			$CI->output->final_output = $this->fetch($template);
			return;
		}
		else {
			return $this->fetch($template);
		}
	}
}
?>